package com.administrator.scoreManageSys.service.impl;

import com.administrator.scoreManageSys.mapper.course.ExamMangeMapper;
import com.administrator.scoreManageSys.service.ExamMangeService;
import com.administrator.scoreManageSys.utils.ResultUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author zsh
 * @date 2022/04/08/ 15:57
 */
@Service
public class ExamMangeServiceImpl implements ExamMangeService {
    @Resource
    private ExamMangeMapper examMangeMapper;
    @Resource
    private ResultUtils resultUtils;

    /**
     * 获取考试管理列表
     *
     * @param pageNum  当前页
     * @param pageSize 页大小
     * @param subject  科目
     * @param season   考季
     * @param name     考试名称
     * @return -
     */
    @Override
    public JSONObject examList(Integer pageNum, Integer pageSize, Long subject, Long season, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list = examMangeMapper.examList(subject,season,name);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return resultUtils.resultSuccessData(pageInfo);
    }

    /**
     * 添加考试
     *
     * @param userId  操作用户id
     * @param season  考季id
     * @param classId 班级id
     * @param subject 科目id
     * @param name    考试名称
     * @return 操作结果
     */
    @Override
    public JSONObject examAdd(Long userId, Long season, Long classId, Long subject, String name) {
        long createTime = System.currentTimeMillis();
        examMangeMapper.examAdd(season,classId,subject,name,userId,createTime);
        return resultUtils.resultSuccess();
    }

    /**
     * 修改考试
     *
     * @param id      考试id
     * @param season  考季id
     * @param classId 班级id
     * @param subject 科目id
     * @param name    考试名称
     * @return 操作结果
     */
    @Override
    public JSONObject examEdit(Long id, Long season, Long classId, Long subject, String name) {
        examMangeMapper.examEdit(season,classId,subject,name,id);
        return resultUtils.resultSuccess();
    }

    /**
     * 删除考试
     *
     * @param id 考试id
     * @return 操作结果
     */
    @Override
    public JSONObject examDelete(Long id) {
        examMangeMapper.examDelete(id);
        return resultUtils.resultSuccess();
    }
}
